﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using Core.CSV;

namespace Game
{
    /// <summary>
    /// 武器的额外效果：可以附加在武器的普通攻击、技能攻击，甚至是其他效果上
    /// 附加的方式是通过获得对应的组件来进行强化
    /// </summary>
    public abstract partial class WeaponEffect : ABSWeaponCombinant
    {
        protected ABSWeaponCombinant mAttachCombinant;//当前绑定到的集合体

        public TBWeaponEffectConfig Data {
            get;
            private set;
        }

        public WeaponEffect(TBWeaponEffectConfig config) {
            Data = config;
        }

        protected ReadOnlyCollection<WeaponEffect> mEffectList;
        protected int mIndex;

        /// <summary>
        /// 只需要知道绑定在哪个集合体上
        /// </summary>
        public void Init(Weapon weapon, List<WeaponEffect> effectList, int curIndex) {
            mAttachCombinant = weapon;
            mEffectList = effectList.AsReadOnly();
            mIndex = curIndex;
            onInit();
        }
        //附加到武器上时触发
        public void Attach() {
            onAttach();
        }
        //武器普通攻击触发时
        public void Trigger() {
            //触发组件
            foreach (var component in mWeaponComponentsDic) {
                component.Value.Trigger();
            }
            onTrigger();
        }

        public void TriggerEnd() {
            onTriggerEnd();
        } 
        //武器技能攻击触发时
        public void SkillTrigger() {
            onSkillTrigger();
        }

        public void SkillTriggerEnd() {
            onSkillTriggerEnd();
        }
        //脱离武器时触发
        public void Detach() {
            onDetach();
        }
        
        protected virtual void onInit() {}
        protected virtual void onAttach(){}
        protected virtual void onDetach(){}
        protected virtual void onTrigger() {}
        protected virtual void onTriggerEnd() {}
        protected virtual void onSkillTrigger() {}
        protected virtual void onSkillTriggerEnd() {}
    }
}